"""
任何类本质上，都是type类

可以用type动态创建类
"""


class A:
    def greeting(self):
        print("hhhh")


print(type(A))
print(isinstance(A, type))


# 可从文件读取
class_body = """
@staticmethod
def hello():
    print("hello world")
    
def dddd(self):
    print("ddd")
"""

class_dict = dict()
# 把这个字符串转换字典
exec(class_body, globals(), class_dict)
# {'hello': <staticmethod object at 0x000001DF05E97E50>, 'dddd': <function dddd at 0x000001DF05FC8A60>}
print(class_dict)

# 动态创建类 类名，父类，
B = type("B", (object,), class_dict)
instance = B()
instance.hello()  # hello world
instance.dddd()  # ddd
B.hello()  # hello world

